{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow.compat.v1 as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "tf.disable_v2_behavior()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD4CAYAAAD8Zh1EAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMSwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/d3fzzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAP6ElEQVR4nO3df4xlZ13H8feH2W1cfrliR0J3V7Ympdjwq3DdxhCRH8JuC7EI/NGiGBqTTZO2wcRUiokaQwyaRkOTFjebUpGIbAwttZLCSiJIDAE72xbKUpZslh87u2inYlFgY7vbr3/cS52d3pl7Z+bOntln369k0znnPPOc73nOnE/PnPvcuakqJElnv2d0XYAkaTIMdElqhIEuSY0w0CWpEQa6JDViQ1c7Pv/882v79u1d7V6SzkoHDhx4tKqmh23rLNC3b9/OzMxMV7uXpLNSku8sts1HLpLUCANdkhphoEtSIwx0SWqEgS5JjRg5yyXJHcBbgEeq6iVDtge4BbgC+DHw7qq6f9KFAtz9wDFu3n+I44+d4ILNm7hx58W89dIta7GrFRtV42LbV3NskxyXYX0BE+m/6/O3XsZYWisZ9dcWk7wG+CHw0UUC/QrgBvqBfhlwS1VdNmrHvV6vljNt8e4HjvG+ux7ixBOnnlq3aeMUH3jbS9fNhTWqxsW2v/1VW7jzwLEVHdskx2VYXxunAgVPPPn/Pycr6b/r87ea/XdduzRfkgNV1Ru2beQjl6r6AvD9JZpcST/sq6q+BGxO8oKVlbq4m/cfOu2CAjjxxClu3n9o0rtasVE1Lrb9418+uuJjm+S4DOvriVN1WpivtP+uz99q9t917dK4JvEMfQtwdN7y7GDd0yTZnWQmyczc3NyydnL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iQv6bikMy7JW4BHqupA17WsA6+uqlcClwPXJXlN1wV1YAPwSuCvqupS4EfATavt1EBfQ4NnxncCH6uqu7qup2uDXyk/T/+jCs81rwZ+Pcm3gX3A65P8bbcldaOqjg/++wjwSWBHtxV1YhaYnffb6ifoB/yqGOhrZPA5qx8GHq6qv+y6nq4kmU6yefD1JuDXgG90WlQHqup9VbW1qrbT/6D1f66q3+q4rDMuybMGkwQYPGJ4E/C1bqs686rq34GjSS4erHoDsOoJE85yWTuvBt4FPDR4fgzwB4PPZz2XvAD4myRT9G8g/r6qztkpe+L5wCf79ztsAP6uqj7TbUmduQH42GCGyxHgmtV26Fv/JakRPnKRpEYY6JLUCANdkhphoEtSIwx0SWqEgS5JjTDQJakR/weN94B4NmAZbgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x_label0=np.random.normal(5,1,10)\n",
    "x_label1=np.random.normal(2,1,10)\n",
    "xs=np.append(x_label0,x_label1)\n",
    "labels=[0.]* len(x_label0)+[1.]*len(x_label1)\n",
    "plt.scatter(xs,labels)\n",
    "learning_rate=0.01\n",
    "training_epochs=1000\n",
    "\n",
    "X=tf.placeholder('float')\n",
    "Y=tf.placeholder('float')\n",
    "def model(X,w):\n",
    "    return tf.add(tf.multiply(w[1],tf.pow(X,1)),\n",
    "                 tf.multiply(w[0],tf.pow(X,0)))\n",
    "w=tf.Variable([0.,0.],name='parameters')\n",
    "y_model=model(X,w)\n",
    "cost=tf.reduce_sum(tf.square(Y-y_model))\n",
    "\n",
    "train_op=tf.train.GradientDescentOptimizer(learning_rate).minimize(cost)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess=tf.Session()\n",
    "init=tf.global_variables_initializer()\n",
    "sess.run(init)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 65.53775\n",
      "100 nan\n",
      "200 nan\n",
      "300 nan\n",
      "400 nan\n",
      "500 nan\n",
      "600 nan\n",
      "700 nan\n",
      "800 nan\n",
      "900 nan\n"
     ]
    }
   ],
   "source": [
    "for epoch in range(training_epochs):\n",
    "    sess.run(train_op,feed_dict={X:xs,Y:labels})\n",
    "    current_cost=sess.run(cost,feed_dict={X:xs,Y:labels})\n",
    "    if epoch %100==0:\n",
    "        print(epoch,current_cost)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "w_val="
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
